<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>回调函数形式的ref</title>
</head>

<body>
    <!--准备好一个容器-->
    <div id="test"></div>
    <!--引入核心库-->
    <script src="../js/react.development.js"></script>
    <!--引入react-dom支持react操纵dom-->
    <script src="../js/react-dom.development.js"></script>
    <!--引入babel用于将jsx转为js-->
    <script src="../js/babel.min.js"></script>
    <!--引入prop-types,用于对标签属性进行限制-->
    <script src="../js/prop-types.js">//引入之后全局会产生一个PropType对象</script>

    <script type="text/babel">
        //创建一个组件
        class Demo extends React.Component {
            showData = () => {
                const { xy1 } = this//通过回调将函数捆绑在了实例对象上 所以通过this来取
                alert(xy1.value)
            }
            showData2 = () => {
                const { xy2 } = this
                alert(xy2.value)
            }
            render() {//类组件中必须加render
                //语法限制标签必须闭合
                return (
                    <div>
                        <input ref={c => this.xy1 = c} type="text" placeholder="点击按钮提示数据" />
                        <button onClick={this.showData}>点我提示左侧的数据</button>
                        <input ref={c => this.xy2 = c} onBlur={this.showData2} type="text" placeholder="失去焦点提示数据" />
                    </div>
                )//标签内属性的写法很重要
            }
        }
        //渲染组件到页面
        //注意DOM大写
        ReactDOM.render(<Demo />, document.getElementById('test'))
    </script>
</body>

</html>